Skip to content

Conversation

teresaromero
Copy link
Contributor

@teresaromero teresaromero commented Sep 25, 2025

Resolves #2797

Summary

Refactored the linked files system to use explicit os.Root parameters for secure repository access. This change fixes a bug where linked files were copied to incorrect directories and reveals a secondary issue where external fields were resolved before linked files were included in the build bundle.

Problems Fixed

  1. Linked files copied to wrong directory: The workDir in LinksFS was treated inconsistently (absolute vs relative), causing incorrect path resolution. Now standardized to always be relative to repository root.

  2. External fields resolved too early: The build process resolved external fields before copying linked files, causing missing field definitions. Reordered build steps to copy linked files first.

Key Changes

Repository Root Handling:

  • CreateLinksFSFromPath() now requires explicit *os.Root parameter
  • All callers must find and pass repository root explicitly
  • Added proper cleanup with defer repositoryRoot.Close()

API Changes:

  • FindPackageRoot() signature: (string, bool, error)(string, error)
  • Added ErrPackageRootNotFound sentinel error
  • BuildOptions.PackageRoot renamed to PackageRootPath and added RepositoryRoot field
  • Package installer Options.RootPath renamed to PackageRootPath and added RepositoryRoot field

Build Process:

  • License file resolution now uses repository root securely
  • Linked files included before resolving external fields
  • ELASTIC_PACKAGE_REPOSITORY_LICENSE now expects paths relative to repository root

Breaking Changes

Functions that previously auto-discovered repository root now require it as a parameter:

  • CreateLinksFSFromPath(repositoryRoot, workDir)
  • BuildPackage() requires RepositoryRoot in options
  • NewForPackage() requires RepositoryRoot in options

Testing

  • All existing tests updated and passing
  • New test coverage for license file handling and edge cases
  • Manual verification confirms fixes for both bugs

@teresaromero teresaromero marked this pull request as ready for review September 30, 2025 13:01
@teresaromero
Copy link
Contributor Author

@mrodm i've updated the code with your feedback. i usually mark resolved the comments that have been addressed, please re-open if you find anything pending.

thanks

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great, it seems to solve links resolution and does a good refactor to allow injection of the path to the root repository.

I did some tests and found some issues, commented in the files, though maybe some of them can be solved in follow ups.

Many comments are nitpicking, no need to do anything about them if you prefer current code.

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great changes here 👍

// elasticsearch/ingest_pipeline under the provided data stream path. The names
// of the pipelines are decorated with the provided nonce.
func LoadIngestPipelineFiles(dataStreamPath string, nonce int64) ([]Pipeline, error) {
func LoadIngestPipelineFiles(dataStreamPath string, nonce int64, repositoryRoot *os.Root) ([]Pipeline, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if these methods should just receive an FS, instead of receiving the root and creating its own 🤔 For another refactor in any case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i think there is room for improvement in following refactor. Also i've notice some of the code around the builder, package paths, build paths, etc... that are a bit confusing so perhaps when we work on the feature to allow builds in any target directory we could have some time to improve that part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor links resolver so it can write to files out of the repository

4 participants